home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue30 / mmapfile / MMAPFILE.ZIP / UMEMX.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1997-06-22  |  2.3 KB  |  105 lines

  1. unit UMemX;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   E_MemMap, Buttons, StdCtrls, Mask, ComCtrls;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     SpeedButton1: TSpeedButton;
  12.     SpeedButton2: TSpeedButton;
  13.     Label1: TLabel;
  14.     NdxEdit: TMaskEdit;
  15.     procedure FormCreate(Sender: TObject);
  16.     procedure FormDestroy(Sender: TObject);
  17.     procedure SpeedButton1Click(Sender: TObject);
  18.     procedure SpeedButton2Click(Sender: TObject);
  19.   private
  20.     { Private declarations }
  21.     EMemMap : TEMemMap;
  22.   public
  23.     { Public declarations }
  24.   end;
  25.  
  26. var
  27.   Form1: TForm1;
  28.  
  29. implementation
  30.  
  31. {$R *.DFM}
  32. Const
  33.       MaxArrSize = 16384;
  34. Type
  35.      IntArr = Array[0..MaxArrSize-1] Of Integer;
  36.      IntArrPtr = ^IntArr;
  37.  
  38. procedure TForm1.FormCreate(Sender: TObject);
  39. Var
  40.    I       : Integer;
  41.    IArr    : IntArrPtr;
  42. begin
  43.   Caption:='Int Array [0..'+IntToStr(MaxArrSize-1)+']';
  44.   EMemMap:=TEMemMap.Create(Self);
  45.   EMemMap.CreateMutex('DAVESMUTEX1');
  46.   If NOT EMemMap.MapExisting('DAVESMAP1',SizeOf(IntArr)) then
  47.   begin
  48.     New(IArr);
  49.     For I:=0 To MaxArrSize-1 do
  50.       IArr^[I]:=I+1;
  51.     Try
  52.       If NOT EMemMap.CreateMemMap('DAVESMAP1',SizeOf(IntArr),IArr^) then
  53.         EMemMap.RaiseMappingException;
  54.     Finally
  55.       Dispose(IArr);
  56.     end;
  57.   end;
  58. end;
  59.  
  60. procedure TForm1.FormDestroy(Sender: TObject);
  61. begin
  62.   EMemMap.Free;
  63. end;
  64. procedure TForm1.SpeedButton1Click(Sender: TObject);
  65. Var
  66.     AnInt : Integer;
  67. begin
  68.   AnInt:=StrToInt(NdxEdit.Text);
  69.   If (AnInt>=0) AND (AnInt<MaxArrSize) then
  70.   begin
  71.     EMemMap.EnterCriticalSection;
  72.     Try
  73.       AnInt:=IntArrPtr(EMemMap.MemMap)^[AnInt];
  74.     Finally
  75.       EMemMap.LeaveCriticalSection;
  76.     end;
  77.     MessageDlg(IntToStr(AnInt),mtInformation,[mbOk],0);
  78.   end;
  79. end;
  80.  
  81. procedure TForm1.SpeedButton2Click(Sender: TObject);
  82. Var
  83.     Ndx    : Integer;
  84.     AnInt  : Integer;
  85.     AValue : String;
  86. begin
  87.   Ndx:=StrToInt(NdxEdit.Text);
  88.   If (Ndx>=0) AND (Ndx<MaxArrSize) then
  89.   begin
  90.     EMemMap.EnterCriticalSection;
  91.     Try
  92.       AnInt:=IntArrPtr(EMemMap.MemMap)^[Ndx];
  93.       AValue:=IntToStr(AnInt);
  94.       InputQuery('Get Value','NewValue',AValue);
  95.       AnInt:=StrToInt(AValue);
  96.       IntArrPtr(EMemMap.MemMap)^[Ndx]:=AnInt;
  97.     Finally
  98.       EMemMap.LeaveCriticalSection;
  99.     end;
  100.   end;
  101. end;
  102.  
  103.  
  104. end.
  105.